package cyou.breathe.tools;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author: breathe
 * @createTime: 2025-06-16
 */
public final class CacheUtils {
    private static final String SPLICING_OPERATOR = "_";

    /**
     * 构建缓存标识
     */
    public static String buildKey(String ... keys) {
        Stream.of(keys).forEach(each -> Optional.ofNullable(Strings.emptyToNull(each)).orElseThrow(() -> new RuntimeException("构建缓存key不允许为空")));
        return Joiner.on(SPLICING_OPERATOR).join(keys);
    }

    /**
     * 判断结果是否为空或空的字符串
     */
    public static boolean isNullOrBlank(Object cacheValue) {
        return cacheValue == null || (cacheValue instanceof String && Strings.isNullOrEmpty((String)cacheValue));
    }
}
